
from AGDefines import  *
import cv2
import os

def genTemplate():
    pass


    #genNormalTemplate("ZhangHao",ZhangHaoActions)
    #genNormalTemplate("Public", publicActions)
    #genNormalTemplate("Public", ShangDianActions)
    #genNormalTemplate("RiChang",RiChangActions)
    #genNormalTemplate('TongJi',TongJiActions)
    #genNormalTemplate("PinTu", PinTuActions)
    #genNormalTemplate("BaoTu", BaoTuActions)
    #genNormalTemplate("SuanGua", SuanGuaActions)
    #genNormalTemplate("ShiMen", ShiMenActions)
    genNormalTemplate('HuanJing', HuanJingActions)
    #genNormalTemplate("KeJu", keJuActions)
    #genNormalTemplate("JuQing", juQingActions)


def genNormalTemplate(daily,actions):

    path = "asserts/"+daily;
    if os.path.exists(path) is False:
        os.makedirs(path)

    for i in range(len(actions)):
        genAnAction(daily,actions[i])


def genAnAction(daily,action):



    path = "{}/{}/{}.png".format(originPath, daily, action[0])
    img = cv2.imread(path)
    if img is None:
        print("cannot load {}".format(path))
        return -1

    cv2.imshow("123", img)
    trect = action[3]
    print("range {} {} {} {}".format(trect[0], trect[2], trect[1], trect[3]))
    tarimg = img[trect[1]:trect[3], trect[0]:trect[2]]
    print("{} action:{}".format(action[0],tarimg.shape))
    cv2.imshow("1233", tarimg)

    path = "asserts/{}/{}.png".format(daily, action[0])
    cv2.imwrite(path, tarimg)
    cv2.waitKey(1)
    return 0